﻿namespace dot_in.HTWKAidStation.Client
{
    using System.Collections.Generic;
    using System.Text;
    using System.Threading.Tasks;

    using Windows.Storage.Search;
    using Windows.Storage.Streams;
    using Windows.UI.Xaml;

    using dot_in.HTWKAidStation.Client.Timetable;

    public static class CachedCore
    {
        public static async Task<List<Faculty>> ParseAllFaculties()
        {
            if (CacheManager.HasCacheOfType<List<Faculty>>())
            {
                return CacheManager.Resolve<List<Faculty>>();
            }

            List<Faculty> faculties = await Core.ParseAllFaculties();
            CacheManager.Register(faculties);
            return faculties;
        }

        public static async Task<List<Week>> ParseAllWeeks()
        {
            if (CacheManager.HasCacheOfType<List<Week>>())
            {
                return CacheManager.Resolve<List<Week>>();
            }

            List<Week> weeks = await Core.ParseAllWeeks();
            CacheManager.Register(weeks);
            return weeks;
        }

        public static async Task<List<EventDay>> ParseTimetable(string tutorialGroupID, string week)
        {
            return await Core.ParseTimetable(tutorialGroupID, week);
        }

        public static async Task<List<Mensa.Mensa>> ParseMensa()
        {
            if (CacheManager.HasCacheOfType<List<Mensa.Mensa>>())
            {
                return CacheManager.Resolve<List<Mensa.Mensa>>();
            }

            List<Mensa.Mensa> mensas = await Core.ParseMensa();
            CacheManager.Register(mensas);
            return mensas;
        }
    }
}
